<template>
  <div class="main">
    <!-- 热门排行榜 -->
    <div class="rankingList">
      <div class="title">热门色号</div>
      <ul>
        <router-link :to="{ path: '/proDetails', query: { i: i } }">
          <li
            v-for="item in product"
            :key="item.id"
            v-show="item.isRanking"
            @click="click(item.id)"
          >
            <img :src="item.icons" alt="" />
            <span class="model">{{ item.model }}</span>
            <span class="name">{{ item.name }}</span>
            <div class="sort">{{ item.id }}</div>
          </li>
        </router-link>
      </ul>
    </div>
    <!-- 笔记分享 -->
    <div class="share">
      <div class="newsList">
        <ul>
          <router-link :to="{ path: '/details', query: { i: i } }">
            <li
              v-for="(item, index) in usersList"
              :key="index"
              @click="click(item.id)"
            >
              <img :src="item.url" alt="" />
              <div class="introduce">{{ item.content }}</div>
              <div class="information">
                <div class="photo">
                  <img :src="item.head" alt="" />
                  <div class="name">{{ item.name }}</div>
                </div>
                <div
                  class="iconfont fabulous"
                  :class="item.isLike == true ? 'active' : ''"
                >
                  &#xe604;{{ item.fabulous }}
                </div>
              </div>
            </li>
          </router-link>
        </ul>
      </div>
    </div>
    <!-- 发表笔记 -->
    <div class="add">
      <router-link to="/release"> + </router-link>
    </div>
  </div>
</template>
<script>
import {foundList} from '@/assets/api/index'
import { mapMutations, mapState } from 'vuex';
export default {
  data() {
    return {
      i: 0,
      usersList:null,
    };
  },
  methods: {
    ...mapMutations(['setUsers']),
    click(i) {
      this.i = i - 1;
    },
  },
  computed:{
    ...mapState(['product','users'])
  },
  mounted(){
    if(!this.users){
      foundList().then(res => {
        this.usersList = res.data.list
        this.$store.commit('setUsers',this.usersList)
      })
    }else{
      this.usersList = this.users
    }
  }
};
</script>
<style scoped lang="scss">
.main {
  padding-top: 60px;
  padding-bottom: 80px;
  .rankingList {
    width: 100%;
    .title {
      padding: 5px 10px;
      box-sizing: border-box;
      width: 100%;
      height: 30px;
      font-size: 16px;
      font-weight: 600;
      line-height: 20px;
    }
    ul {
      height: 120px;
      padding: 0px 8px;
      box-sizing: border-box;
      box-shadow: 2px 2px 4px #ccc;
      a {
        display: flex;
        overflow-x: auto;
        li {
          background: #f7f7f7;
          height: 110px;
          flex: 0 0 70px;
          margin: 0 2px;
          display: flex;
          flex-direction: column;
          box-sizing: border-box;
          border-radius: 10px;
          position: relative;
          img {
            border-radius: 10px;
            width: 100%;
            height: 70px;
          }
          span {
            display: block;
            width: 100%;
            height: 20px;
            font-size: 12px;
            text-align: center;
            line-height: 20px;
            color: rgb(124, 124, 124);
          }
          .model {
            color: #000;
          }
          .sort {
            position: absolute;
            top: 0;
            left: 0;
            width: 18px;
            height: 18px;
            font-size: 12px;
            text-align: center;
            line-height: 18px;
            color: #fff;
            background: #d5a77d;
            border-top-left-radius: 10px;
            border-bottom-right-radius: 10px;
          }
        }
        li:nth-child(1) .sort {
          background: #eb5e32;
        }
        li:nth-child(2) .sort {
          background: #fa7d2a;
        }
        li:nth-child(3) .sort {
          background: #f5b941;
        }
      }
      a::-webkit-scrollbar {
        display: none;
      }
    }
  }
  .share {
    // margin-top: 10px;
    width: 100%;
    background: #fccde7;
    padding: 10px 0;
    .title {
      width: 200px;
      height: 50px;
      margin: 0 auto;
      background: #fa6ba1;
      border-radius: 20px;
      color: #fff;
      font-size: 22px;
      text-align: center;
      line-height: 50px;
    }
    .newsList {
      width: 100%;
      ul {
        padding: 5px;
        box-sizing: border-box;
        a {
          display: flex;
          flex-wrap: wrap;
          justify-content: space-between;
          li {
            margin: 2px 0;
            border-radius: 5px;
            flex-basis: 49.5%;
            height: 300px;
            display: flex;
            flex-direction: column;
            background: #fff;
            padding: 2px;
            box-sizing: border-box;
            box-shadow: 2px 2px 4px #ccc;
            > img {
              border-top-left-radius: 5px;
              border-top-right-radius: 5px;
              width: 100%;
              height: 220px;
            }
            .introduce {
              padding: 0 5px;
              box-sizing: border-box;
              width: 100%;
              height: 40px;
              font-size: 14px;
              line-height: 20px;
              display: -webkit-box;
              overflow: hidden;
              text-overflow: ellipsis;
              -webkit-box-orient: vertical;
              -webkit-line-clamp: 2;
            }
            .information {
              width: 100%;
              height: 40px;
              display: flex;
              justify-content: space-between;
              .photo {
                flex-basis: 60%;
                display: flex;
                img {
                  margin-top: 5px;
                  width: 30px;
                  height: 30px;
                  border-radius: 50%;
                }
                .name {
                  font-size: 14px;
                  line-height: 40px;
                  overflow: hidden;
                  text-overflow: ellipsis;
                  white-space: nowrap;
                }
              }
              .fabulous {
                flex-basis: 40%;
                font-size: 14px;
                line-height: 40px;
                text-align: right;
                color: rgb(99, 99, 99);
              }
              .active {
                color: red;
              }
            }
          }
        }
      }
    }
  }
  .add {
    a {
      width: 50px;
      height: 50px;
      position: fixed;
      right: 5px;
      bottom: 100px;
      background: rgb(177, 177, 177);
      border-radius: 10px;
      box-shadow: 2px 2px 4px #ccc;
      line-height: 48px;
      text-align: center;
      color: #fff;
    }
  }
}
</style>